/**
 * 
 */
package ca.uwindsor.cs.deepweb.utility;

import java.io.File;

/**
 * @author Liang Jie
 * 
 */
public class SmallFilesMover {
	protected File sourceDIR;

	protected File destDIR;

	protected int offset;

	protected long filesquality;

	protected long dirquality;

	protected String dir;

	public SmallFilesMover(String sourcepath, String destpath) {
		dir = sourcepath;
		dirquality = 0;
		filesquality = 0;
		offset = 1;
		sourceDIR = new File(sourcepath);
		destDIR = new File(destpath);
	}

	public void move(long length) {

		File[] dataFiles = sourceDIR.listFiles();
		System.out.println("Start to moving the files!");
		for (int i = 0; i < dataFiles.length; i++) {
			File file = dataFiles[i];
			if (file.isFile() && file.getName().endsWith(".txt")
					&& file.length() < length) {
				filesquality++;
				boolean flag = file.renameTo(new File(destDIR
						+ java.io.File.separator + file.getName()));
				if (!flag) {
					System.err.println("Error when moving: " + file.getName());
				}
			}
		}
		System.out.println(filesquality + " files has been moved!");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		args = new String[3];
//		args[0] = "SourceData//en_wiki";
//		args[1] = "SourceData//exp";
//		args[2] = "1000";
		SmallFilesMover mover = new SmallFilesMover(args[0], args[1]);
		mover.move(Integer.parseInt(args[2]));

	}

}
